package com.summer.ChengXuYuanMianShiJingDian;

public class Q3_1 {
    static class TripleInOne{
        int size;
        int top1;
        int top2;
        int top3;
        int[] arr ;
        public  TripleInOne(int stackSize) {
            top1=stackSize;
            top2=2*stackSize+1;
            top3=3*stackSize+2;
            size = stackSize;
            arr = new int[stackSize*3+3];
        }

        public void push(int stackNum, int value) {
            switch (stackNum){
                case 0:
                    if (top1>0) arr[top1--]=value;
                    break;
                case 1:
                    if (top2>size+1) arr[top2--]=value;
                    break;
                case 2:
                    if (top3>2*size+2) arr[top3--]=value;
                    break;
            }
        }

        public int pop(int stackNum) {
            switch (stackNum){
                case 0:
                    if (top1==size) return -1;
                    else {
                        int num = arr[top1+1];
                        arr[top1+1]=0;
                        top1++;
                        return num;
                    }
                case 1:
                    if (top2==2*size+1) return -1;
                    else {
                        int num = arr[top2+1];
                        arr[top2+1]=0;
                        top2++;
                        return num;
                    }
                case 2:
                    if (top3==3*size+2) return -1;
                    else {
                        int num = arr[top3+1];
                        arr[top3+1]=0;
                        top3++;
                        return num;
                    }
            }
        return -1;
        }

        public int peek(int stackNum) {
            switch (stackNum){
                case 0:
                    if (top1==size) return -1;
                    else return arr[top1+1];
                case 1:
                    if (top2==2*size+1) return -1;
                    else return arr[top2+1];
                case 2:
                    if (top3==3*size+2) return -1;
                    else return arr[top3+1];
            }
            return -1;
        }

        public boolean isEmpty(int stackNum) {
            switch (stackNum){
                case 0:
                    if (top1==size) return true;
                    else return false;
                case 1:
                    if (top2==2*size+1) return true;
                    else return false;
                case 2:
                    if (top3==3*size+2) return true;
                    else return false;
            }
            return false;
        }


    }
    public static void main(String[] args) {
        TripleInOne tripleInOne = new TripleInOne(18);
        System.out.println(tripleInOne.peek(1));
        System.out.println(tripleInOne.pop(2));
        System.out.println(tripleInOne.isEmpty(1));
        tripleInOne.push(2,40);
        System.out.println(tripleInOne.pop(2));

    }

}
